<?php
namespace frontend\controllers;

use Codeception\Module\Yii2;
use common\models\MobileRange;
use GK\JavascriptPacker;
use Overtrue\Pinyin\Pinyin;
use yii\web\Controller;
use yii\web\Response;

/**
 * Site controller
 */
class LifeController extends Controller
{

    public $enableCsrfValidation = false;

    /**
     * Displays homepage.
     *
     * @return mixed
     */
    public function actionIndex()
    {
        return $this->render('index');
    }

    public function actionCar()
    {

        if (\Yii::$app->request->isPost){
            $c1=\Yii::$app->request->post('c1');
            $c2=\Yii::$app->request->post('c2');
            $c3=\Yii::$app->request->post('c3');
            $path=\Yii::getAlias('@frontend') .'\config\carno.json';
            $content=file_get_contents($path);
            $cardata=json_decode($content,1);

            $find=null;
            foreach ($cardata as $car){
                if (($c1.$c2)==$car['code']){
                    $find=$car;
                    break;
                }
            }
            if (is_null($find)){
                return json_encode(['status'=>1,'msg'=>'号牌错误']);
            }
            $find['number']=strtoupper($c1.$c2.' '.$c3);
            return json_encode(['status'=>0,'data'=>$find]);

        }







        return $this->render('car');


    }


    public function actionMobile()
    {

        if (\Yii::$app->request->isPost){
            $c3=\Yii::$app->request->post('c3');
            $r=MobileRange::find()->where('prefix='.substr($c3,0,7))->one();
            if (!$r){
                return json_encode(['status'=>1,'msg'=>'未找到归属错误']);
            }
            return json_encode(['status'=>0,'data'=>[
                'provice'=>$r->provice,
                'city'=>$r->city,
                'operator'=>$r->operator,
                'zone'=>$r->zone,
                'code'=>$r->code,

            ]]);

        }

        return $this->render('mobile');


    }

    public function actionBmi(){
        return $this->render('bmi');
    }
    public function actionShencai(){
        return $this->render('shencai');
    }
}
